<!DOCTYPE html >
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title>经纪人列表</title>
  <link rel="stylesheet" href="/lib/layui/css/layui.css" media="all">
  <link href="/lib/css/bootstrap.min.css" rel="stylesheet">
  <link href="/lib/css/materialdesignicons.min.css" rel="stylesheet">
  <link href="/lib/css/style.min.css" rel="stylesheet">
</head>
<style>
  .layui-table{
    width: 100%!important;
  }
</style>

<body>
<div class="container-fluid p-t-15">

  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-toolbar clearfix">
          <form class="pull-right search-bar" method="get" action="#!" role="form">
            <div class="input-group">
              <input id="sname" type="text" class="form-control" placeholder="请输入举报人姓名">
              <span class="input-group-btn">
                                <button id="search" class="btn btn-default" type="button">搜索</button>
              </span>
            </div>
          </form>
          <div class="toolbar-btn-action">
            <a class="btn btn-primary m-r-5" id="add1" href="#!"><i class="mdi mdi-plus"></i>举报信息添加</a>
          </div>
        </div>
        <input type="hidden" th:value="${mid}" id="mid">
      </div>
    </div>

  </div>

</div>
<table id="demo" lay-filter="test"></table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>



<script src="/lib/layui/layui.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.11.2/jquery.js"></script>



<script type="text/javascript" th:inline="none">
  layui.use(['element','jquery','table','layer'], function(){
    var element = layui.element;
    var layer = layui.layer;
    var table = layui.table;
    var $ = layui.jquery;

    //第一个实例
    table.render({
      elem: '#demo'
      ,height: 312
      ,url: '/reportlist?reporter'+"" //数据接口
      ,page: true //开启分页
      ,cols: [[ //表头
        {field: 'id', title: 'ID', width:60, sort: true, fixed: 'left'}
        ,{field: 'reporter', title: '举报人', width:80, align:'left'}
        ,{field: 'reportertel', title: '举报人电话', width:124,align:'left'}
        ,{field: 'informant', title: '被举报人', width:118, sort: true, align:'left'}
        ,{field: 'createtime', title: '举报时间', width:230, sort: true, align:'left',
          templet:"<div>{{layui.util.toDateString(d.ordertime, 'yyyy年MM月dd日 HH:mm:ss')}}</div>"}
        ,{field: 'description', title: '举报描述', width:107, sort: true, align:'left'}
        ,{field: 'status', title: '状态', width:81, sort: true, align:'left'}
        ,{fixed: 'right', title: '操作',width: 175, align:'left', toolbar: '#barDemo'}
      ]]
    });
    //监听行工具事件
    table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
      var data = obj.data //获得当前行数据
              ,layEvent = obj.event; //获得 lay-event 对应的值
      var id = data.id;
      if(layEvent === 'detail'){
        layer.open({
          type:2,
          content:'/rdetail?id='+id,
          area: ['600px', '400px'],
        })

      } else if(layEvent === 'del'){
        layer.confirm('真的删除该条信息么', function(index){
          obj.del(); //删除对应行（tr）的DOM结构
          layer.close(index);
          $.ajax({
            url:"/reportdelete",
            type:'post',
            data:{ id:id},
            datatyp:'json',
            success:function (message) {
              if (message.code==0){
                alert("删除成功！")
              }else {
                alert("删除失败！")
              }
            }
          })

        });
      } else if(layEvent === 'edit'){
        layer.open({
          type: 2,
          content:'/reportinfo?id='+id,
          where:{
            id:data.id
          },
          area: ['600px', '600px'],
          end:function (){
            //重新加载table表格
            table.reload('demo');
          }
        })
      }
    });

    $("#add1").on('click',function () {
      layer.open({
        type:2,
        title:"举报信息添加",
        content:"/reportadd",
        area: ['600px', '400px'],
        end:function (){
          table.reload('demo');
        }
      })
    });
    $("#search").on('click',function () {
      table.reload('demo',{
        url:'/reportlist'//数据接口ajax
        ,where:{//条件查询
          reporter:$('#sname').val(),
          id:$("#mid").val()
        }
        ,page:{
          curr:1
        }
      })
      return false;
    })
  });

</script>
</body>
</html>